#include "head.h"

int short_cmd(int socket_fd, char *cmd_head, char *cmd_body, char *cmd_backup, char *cur_path){

    if(strcmp(cmd_head, "cd") == 0){
        char buf[100] = {0};
        //printf("cmd_head = %s\n", cmd_head);
        //printf("cmd_body = %s\n", cmd_body);
        send(socket_fd, cmd_backup, strlen(cmd_backup), 0);
        recv(socket_fd, buf, sizeof(buf), 0);
        //printf("%s\n", buf);
        bzero(cur_path, sizeof(cur_path));
        recv(socket_fd, cur_path, 1024, 0);

    }
    else if (strcmp(cmd_head, "rm") == 0){
        //printf("cmd_head = %s\n", cmd_head);
        send(socket_fd, cmd_backup, strlen(cmd_backup), 0);
    }
    else if(strcmp(cmd_head, "mkdir") == 0){
        //printf("cmd_head = %s\n", cmd_head);
        send(socket_fd, cmd_backup, strlen(cmd_backup), 0);
    }
    else if(strcmp(cmd_head, "ls") == 0){
        //printf("cmd_head = %s\n", cmd_head);
        //printf("cmd_backup = %s\n", cmd_backup);
        send(socket_fd, cmd_backup, sizeof(cmd_backup), 0);
        char res_buf[1024] = {0};
        while(1){
            recv(socket_fd, res_buf, sizeof(res_buf), 0);
            if(strncmp(res_buf, "1", 1) == 0){
                break;
            }
            printf("%s\n", res_buf);
        }
    }
    else if(strcmp(cmd_head, "pwd") == 0){
        //printf("cmd_head = %s\n", cmd_head);
        //printf("cmd_backup = %s\n", cmd_backup);
        send(socket_fd, cmd_backup, sizeof(cmd_backup), 0);
        char res_buf[1024] = {0};
        recv(socket_fd, res_buf, sizeof(res_buf), 0);
        printf("%s\n", res_buf);
    } 
    else if(strcmp(cmd_head, "undorm") == 0){
        //printf("cmd_head = %s\n", cmd_head);
        //printf("cmd_backup = %s\n", cmd_backup);
        send(socket_fd, cmd_backup, strlen(cmd_backup), 0);
        char res_buf[1024] = {0};
        recv(socket_fd, res_buf, sizeof(res_buf), 0); 
        printf("%s\n", res_buf);
    }
    //printf("short_cmd_over\n");
    return 0;
}
